﻿using System;
using System.Linq;
using ProjetoComperio.DataLayer.Entities;
using ProjetoComperio.DataLayer.Infra;

namespace ProjetoComperio.BusinessLogicLayer
{
    public class ContributionItemBLL : ComperioDataObject
    {
        /// <summary>
        /// This method creates a new contributionItem in db
        /// </summary>
        /// <param name="comment"></param>
        public void Create(ContributionItem contributionItem)
        {
            DbContext.ContributionItems.Add(contributionItem);
            DbContext.SaveChanges();
        }

        /// <summary>
        /// This method retrieves a specific contributionItem from db
        /// </summary>
        /// <param name="comment"></param>
        public ContributionItem RetrieveContributionItem(Int32 contributionItemID)
        {
            return DbContext.ContributionItems.Where(contributionItem => contributionItem.ContributionItemID == contributionItemID).FirstOrDefault();
        }

        /// <summary>
        /// This method retrieves a specific contributionItem from db
        /// </summary>
        /// <param name="comment"></param>
        public void Remove(Int32 contributionItemID)
        {
            DbContext.ContributionItems.Remove(RetrieveContributionItem(contributionItemID));
            DbContext.SaveChanges();
        }

        /// <summary>
        /// This method retrieves the contributionItems related to specific contribuition
        /// </summary>
        /// <param name="contributionID"></param>
        /// <returns></returns>
        public IQueryable<ContributionItem> RetrieveContributionItems(int contributionID)
        {
            return DbContext.ContributionItems.Where(contributionItem => contributionItem.ContributionID == contributionID);
        }
    }
}
